﻿using System.Collections;
using System.Reflection;

namespace QuickORM.BLL
{
    public class BLLFactory<T> where T : class
    {
        private static readonly Hashtable objCache = new Hashtable();
        private static readonly object syncRoot = new object();

        public static T Instance
        {
            get
            {
                var CacheKey = typeof (T).FullName;
                var bll = (T) objCache[CacheKey]; //从缓存读取  
                if (bll == null)
                {
                    lock (syncRoot)
                    {
                        if (bll == null)
                        {
                            bll = Reflect<T>.Create(typeof (T).FullName, Assembly.GetExecutingAssembly().GetName().Name); //反射创建，并缓存
                            objCache.Add(typeof (T).FullName, bll);
                        }
                    }
                }
                return bll;
            }
        }
    }
}